PHP用inotify扩展监控文件 |
您所在的位置:网站首页 › php 监控文件夹变动 › PHP用inotify扩展监控文件 |
PHP用inotify扩展监控文件
可以用inotify扩展提供的功能来监控文件/目录,实现某些特殊的功能:如热编译,安全预警。 早期phpStudy有提供防挂马功能,就是用了与inotifyf类似的机制。 inotify扩展提供了一系列inotify函数:inotify_init() inotify_add_watch() inotify_rm_watch()。 类似C语言里的inotify_init()函数会返回文件描述符,PHP的inotify_init()则返回 stream资源。可以被标准的Stream函数使用,例如 stream_select() stream_set_blocking(),以及fclose()。 1. 安装 $ pecl install inotify安装后在php.ini中加上 extension=inotify.so 2. 函数概览 2.1 inotify_init用于初始化一个inotify实例。 函数原型: resource inotify_init(void)失败则返回FALSE 2.2 inotify_add_watch添加一个文件或文件夹至监控列表中。如果已经存在,则视为修改。 函数原型: int inotify_add_watch(resource $inotify_instance, string $pathname, int $mask) $inotify_instance inotify_init()返回的资源 $pathname 要监控的文件或文件夹 $mask 要监控的事件该函数的返回值是一个唯一的监控描述符。可以在inotify_rm_watch()中使用,用于移除对它的监控。 2.3 inotify_read从inotify instance中读取事件。 函数原型: array |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |